package com.example.demo.register;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.config.springsecurity.UserInfo;
import com.example.demo.config.springsecurity.UserInfoMapper;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

@Service
public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> implements UserInfoService {

    @Override
    public boolean save(UserInfo userInfo) {
        if (userInfo.getName() == null || userInfo.getPassword() == null) {
            return false;
        }
        BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
        userInfo.setPassword(passwordEncoder.encode(userInfo.getPassword()));
        return super.save(userInfo);
    }
}
